package stuMaiFrame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rORM.core.Query;
import com.rORM.core.QueryFactory;

import database.Student;
import login.login;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;

public class StuMainFrame extends JFrame {
	private int id;
	private JPanel contentPane;
	private Student stu = new Student();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StuMainFrame frame = new StuMainFrame(16402);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StuMainFrame(int id) {
		setVisible(true);
		this.id = id ;
		stu = getStuInfo (id);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(449, 313);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu Option = new JMenu("操作");
		menuBar.add(Option);
		
		JMenuItem menuItem = new JMenuItem("查看我的成绩");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SelectGrades(stu);
			}
		});
		Option.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("修改我的信息");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new UpdateStuInfo(stu);
			}
		});
		Option.add(menuItem_1);
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel(stu.getName());
		lblNewLabel.setForeground(Color.RED);
		lblNewLabel.setFont(new Font("Dialog", Font.PLAIN, 20));
		lblNewLabel.setBounds(42, 100, 89, 27);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel("欢迎使用学生管理系统");
		label.setFont(new Font("Dialog", Font.PLAIN, 16));
		label.setBounds(143, 100, 267, 27);
		contentPane.add(label);
		
		JButton btnNewButton = new JButton("退出登录");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new login();
				setVisible(false);
			}
		});
		btnNewButton.setBounds(339, 207, 89, 29);
		contentPane.add(btnNewButton);
	}
	

	public Student getStuInfo(int id){
		Student s = new Student();
		Query q = QueryFactory.createQuery();
		s = (Student)q.queryUniqueRow("select * from student where id = ?", Student.class, new Object[]{id});
			return s;
	}
}
